#include <iostream>
#include <cstring>

using i64 = long long;

constexpr int N = 110;

int g[N][N];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m;
    std::cin >> n >> m;

    std::memset(g, 0x3f, sizeof g);
    for (int i = 0; i < m; ++i) {
        int u, v, w;
        std::cin >> u >> v >> w;
        g[u][v] = g[v][u] = std::min(w, g[u][v]);
    }

    for (int i = 1; i <= n; ++i) {
        g[i][i] = 0;
    }

    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                g[i][j] = g[j][i] = std::min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            std::cout << g[i][j] << " \n"[j == n];
        }
    }

    return 0;
}